﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace NetBase.Net
{
    [TestClass]
    public class RelTest
    {
        class Class1 : BaseElem
        {
            public int X;
        }

        class Class2 : BaseElem
        {
            public int Y;
        }

        [TestMethod]
        public void TestRelClass()
        {
            Class1 cl1 = new Class1() { X = 1 };
            Class2 cl2 = new Class2() { Y = 2 };
            Rel<Class1, Class2> rel = new Rel<Class1, Class2>(cl1, ConTag.HasChildXY, cl2, ConTag.HasParentLayer);
            Assert.AreEqual(1, rel.Me.X);
            Assert.AreEqual(2, rel.OtherRel.Me.Y);
            Assert.AreEqual(rel.OtherRel.Other, rel.Me);
            Assert.AreEqual(rel.Other.Y, 2);
            Assert.AreEqual(rel.OtherRel.OtherTag, ConTag.HasChildXY);
        }

        [TestMethod]
        public void TestListOfRel()
        {
            Class1 cl1 = new Class1() { X = 1 };
            Class2 cl2 = new Class2() { Y = 2 };
            List<IRel> rels = new List<IRel>();
            rels.Add(new Rel<Class1, Class2>(cl1, ConTag.HasChildXY, cl2, ConTag.HasParentLayer));
            rels.Add(new Rel<Class2, Class1>(cl2, ConTag.HasChildXY, cl1, ConTag.HasParentLayer));
            foreach (var rel in rels)
            {
                Console.Out.WriteLine("Rel - Me:{0} MeTag:{1} Other:{2} OtherTag:{3} OtherRel.Me:{4}", rel.Me, rel.MeTag, rel.Other, rel.OtherTag, rel.OtherRel.Me);
            }
        }

        [TestMethod]
        public void TestLayerInitialization1()
        {
            // 4000x3000 - 4 сек
            SqImgLayer l = new SqImgLayer(1000, 1000);
            l.test1();
        }

        [TestMethod]
        public void TestLayerInitialization2()
        {
            // 2000x3000 - 2 сек
            SqImgLayer l = new SqImgLayer(10, 10);
            l.test2();
        }

        [TestMethod]
        public void TestSortedListForRelations()
        {
            List<IRel> rels = new List<IRel>();
            SqRt p1 = new SqRt(1, 1); p1.setInput(NetBase.ColorMath.ColorWeight.ConvertToDrawingColor(Colors.Red));
            SqRt p2 = new SqRt(1, 2); p1.setInput(NetBase.ColorMath.ColorWeight.ConvertToDrawingColor(Colors.Red));
            var r = new Rel<SqRt, SqRt>(p1, ConTag.RightToMe, p2, ConTag.LeftToMe);
            rels.Add( r);
            rels.Add( r.OtherRel);
            rels.Add(r);
            rels.Add(r.OtherRel);
            var list = rels.Where(p => p.MeTag == ConTag.LeftToMe);
            Assert.AreEqual(2, list.Count());

        }


    }
}
